<?php
namespace LRC\TwigExtensions;

/**
 * @package Label
 * @version 1.0.0.0
 * @author J.Minchev
 * @internal 
 * @todo
 */
class Label implements \sCore\TwigExtensions\ExtensionI {

	private $TwigEnvironment;

	public function setTwigEnvironment(\Twig_Environment $Loader) {
		$this->TwigEnvironment = $Loader;
	}

	public function load() {
		$EntityManager = \App\Kernel::instance()->getApplication()->getEntityManager();
		$function = new \Twig_SimpleFunction('label', function ($key) use ($EntityManager) {
							$Label = $EntityManager->getRepository('LRC\Entity\Label')->findOneByKey($key);
							if ($Label) {
								return $Label->getValue();
							}
							return $key;
						});
		$this->TwigEnvironment->addFunction($function);
	}

}